﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using RedDragon.Common.Domain.Manufacture;
using RedDragon.Common.Dtos;
using RedDragon.ERP.API.Application.Commands.Resource;
using T.Common.Domain.Common;

namespace RedDragon.ERP.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ResourceController : ControllerBase
    {
        private readonly IMediator mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public ResourceController(IMediator mediator)
        {
            this.mediator = mediator;
        }

        /// <summary>
        /// 资源列表
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result<PageResultDto<Resources>>> QueryResource(QueryResourceCommand cmd)
        {
            return await mediator.Send(cmd);
        }

        /// <summary>
        /// 资源添加
        /// </summary>
        /// <param name="cmd"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<Result> CreateResource(CreateResourceCommand cmd)
        {
            cmd.CreatedTime = DateTime.Now;
            return await mediator.Send(cmd);
        }
    }
}
